package com.hzit.mmcb.core.controller.api;


import com.hzit.common.result.R;
import com.hzit.mmb.base.utils.JwtUtils;
import com.hzit.mmcb.core.pojo.entity.BorrowInfo;
import com.hzit.mmcb.core.service.BorrowInfoService;
import io.jsonwebtoken.Jwt;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.util.function.Predicate;

/**
 * <p>
 * 借款信息表 前端控制器
 * </p>
 *
 * @author ljh
 * @since 2024-08-27
 */
@RestController
@RequestMapping("/api/core/borrowInfo")
@Api(tags = "借款信息")
public class ApiBorrowInfoController {

    @Autowired
    private BorrowInfoService borrowInfoService;

    /**
     * 获取申请状态
     * @param token
     * @return
     */
    @GetMapping("/auth/getBorrowInfoStatus")
    @ApiOperation("获取申请状态")
    public R getBorrowInfoStatus(@RequestHeader("token") String token){
        Long userId = JwtUtils.getUserId(token);
        Integer status=borrowInfoService.getBorrowInfoStatus(userId);
        return R.ok().data("borrowInfoStatus",status);
    }
    /**
     * 提交
     */
    @PostMapping("/auth/save")
    @ApiOperation("提交表单")
    public R save(@RequestBody BorrowInfo borrowInfo,@RequestHeader("token") String token){
        borrowInfoService.saveByForm(borrowInfo,token);
        return R.ok().message("提交成功");
    }
}

